﻿CREATE PROCEDURE [dbo].[proc_Finance_RunningAccount_GetList_AccountsTypeIdCount]
	(
		@CompanyId int,
		@StartDate nvarchar(10),
		@EndDate nvarchar(10),
		@PaymentTypeId int,
		@BankId int,
		@Renling int,
		@Stext nvarchar(50),
		@AccountsTypeId int
	)
AS
	Select Count(Id),IsNULL(Sum(Case @AccountsTypeId When 1 Then Income Else Outlay End),0) From Finance_RunningAccount R 
	Where (@CompanyId=0 Or R.CompanyId=@CompanyId) and R.AccountsTypeId=@AccountsTypeId and (@PaymentTypeId=0 Or R.PaymentTypeId=@PaymentTypeId)
	and(@BankId=0 Or R.BankId=@BankId) and (@Renling=0 Or R.Renling=@Renling)
	and (@Stext='' Or R.Summary like '%'+ @Stext +'%') and Convert(nchar(10),R.TradeDate,120) between @StartDate and @EndDate
	RETURN
